<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
    <button onclick="buttonClick()">执行</button>
</body>
<script>
    function throttle(fn,wait){
        let lastTime = 0
        let timer = null
        return function (...attr){
            const currentTime = Date.now()
            const remaining = wait - (currentTime - lastTime)
            if(remaining <= 0){
                if(timer){
                    clearTimeout(timer)
                    timer = null
                }
                fn.apply(this,attr)
                lastTime = currentTime
            } else if(!timer){
                timer = setTimeout(()=>{
                    fn.apply(this,attr)
                    lastTime = Date.now()
                    timer = null
                },remaining)
            }
        }
    }
    let buttonClick = throttle(() => {
        console.log(Date.now())
    },1000)
</script>
</html>